<template>
  <div>
    <search @search="handleSearchByKeyword" @add="handleOpenDialog" />
    <ms-table :table-props="tableProps" :data-api="dataUrl" ref="dataTable">
      <el-table-column label="操作" slot="tool">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleOpenDialog(scope.row.userId)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            >删除</el-button>
        </template>
      </el-table-column>
    </ms-table>
    <info ref="infoForm" :title="title" :dialog-visible="dialog1" :form-id="formId" @dataFresh="handleCanleDialog" @close="handleCanleDialog" />
  </div>
</template>

<script>
import { MsTable } from '@/common/table'
import Info from './Info'
import Search from './Search'
import common from '@/mixins/common'
export default {
  components: {
    MsTable,
    Info,
    Search
  },
  mixins: [common],
  props: ['depId'],
  watch: {
    depId: {
      immediate: true,
      handler(depId) {
        this.searchForm.depId = depId
        this.handleFreshTable()
      }
    }
  },
  data() {
    return {
      tableProps: [
        { index: 'username', label: '用户名' },
        { index: 'realName', label: '姓名' },
        { index: 'email', label: '邮箱' },
        { index: 'updateTime', label: '更新时间' }
      ],
      dataUrl: '/sys/user/list',
      searchForm: {},
      roleDialog: false,
      userId: '',
      mainTitle: '用户'
    }
  },
  methods: {
    openDialogConditions(formId) {
      const openFlag = !formId && !this.depId
      if (openFlag) {
        this.$notify({
          title: '提示',
          type: 'warning',
          duration: 2500,
          message: '请选择部门后在进行添加操作'
        })
      }
      return openFlag
    }
  }
}
</script>
